package cn.edu.wfit.modules.learn.controller.coursemanagement;

import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.web.page.TableDataInfo;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.learn.domain.WfitCourse;
import cn.edu.wfit.modules.learn.service.coursemangement.IWfitCourseService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程Controller
 *
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/course")
public class WfitCourseController extends BaseController {
    @Autowired
    private IWfitCourseService wfitCourseService;

    /**
     * 查询课程列表
     */
    @RequiresPermissions("system:course:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitCourse wfitCourse) {
        startPage();
        List<WfitCourse> list = wfitCourseService.selectWfitCourseList(wfitCourse);
        return getDataTable(list);
    }

    @GetMapping("/listById/{studentId}")
    public AjaxResult listDetail(@PathVariable("studentId") String studentId) {
        startPage();
        List<WfitCourse> list = wfitCourseService.selectListById(studentId);
        return success(list);
    }

    /**
     * 导出课程列表
     */
    @RequiresPermissions("system:course:export")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitCourse wfitCourse) {
        List<WfitCourse> list = wfitCourseService.selectWfitCourseList(wfitCourse);
        ExcelUtil<WfitCourse> util = new ExcelUtil<WfitCourse>(WfitCourse.class);
        util.exportExcel(response, list, "课程数据");
    }

    /**
     * 获取课程详细信息
     */
    @RequiresPermissions("system:course:query")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId) {
        return success(wfitCourseService.selectWfitCourseByCourseId(courseId));
    }

    /**
     * 新增课程
     */
    @RequiresPermissions("system:course:add")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitCourse wfitCourse) {
        return toAjax(wfitCourseService.insertWfitCourse(wfitCourse));
    }

    /**
     * 修改课程
     */
    @RequiresPermissions("system:course:edit")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitCourse wfitCourse) {
        return toAjax(wfitCourseService.updateWfitCourse(wfitCourse));
    }

    /**
     * 删除课程
     */
    @RequiresPermissions("system:course:remove")
    @Log(title = "课程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds) {
        return toAjax(wfitCourseService.deleteWfitCourseByCourseIds(courseIds));
    }
}
